package com.liaojp.cmsweb.Result;

import lombok.Data;

/**
 * 给前端返回的json格式的数据
 */
@Data
public class AjaxResult {
    /**
     * 响应码：以 0 结尾（包括0）-成功；其它：失败
     */
    private int resultCode;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 响应数据
     */
    private Object data;

    public static AjaxResult success() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setResultCode(0);
        return ajaxResult;
    }

    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setResultCode(0);
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success(String msg, Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setResultCode(0);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult error(int resultCode, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setResultCode(resultCode);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult error(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setResultCode(-1);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult error(int resultCode) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setResultCode(resultCode);
        return ajaxResult;
    }
}
